const path = require('path');
const { CleanPlugin, DllReferencePlugin } = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
// const utils = require('utils');
const AssetHtmlWebpackPlugin = require('add-asset-html-webpack-plugin');
const WebpackBar = require('webpackbar');
const webpackbar = new WebpackBar({
  color: '#85d', // 默认green，进度条颜色支持HEX
  basic: false, // 默认true，启用一个简单的日志报告器
  profile: false, // 默认false，启用探查器。
});
const config = {
  entry: {
    app: './src/index.tsx',
  },
  build: {
    assetsPublicPath: '../dist',
  },
};
module.exports = {
  entry: config.entry.app,
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, '../dist'),
  },
  // import xxx from './xxx/xxx'
  module: {
    rules: [
      {
        test: /\.(js|jsx)?$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env', '@babel/preset-react'],
            plugins: [
              '@babel/plugin-proposal-class-properties',
              '@babel/plugin-proposal-object-rest-spread',
              '@babel/plugin-transform-runtime',
            ],
          },
        },
      },
      {
        test: /\.(tsx|ts)?$/,
        use: 'ts-loader',
        exclude: /node_modules/,
      },
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader'],
      },
      // {
      //   test: /\.scss$/,
      //   use: ["style-loader", "css-loader", "sass-loader"],
      // },
      {
        test: /\.(png|svg|jpg|gif)$/,
        use: ['file-loader'],
      },
      {
        test: /\.(woff|woff2|eot|ttf|otf)$/,
        use: ['file-loader'],
      },
    ],
  },
  resolve: {
    extensions: ['.ts', '.tsx', '.js', '.jsx'],
    alias: {
      '@': path.resolve(__dirname, '../src'),
    },
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './public/index.html',
    }),
    webpackbar,
    // new webpack.DefinePlugin({
    //   "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
    // }),
    // new webpack.HotModuleReplacementPlugin(),
    // new CleanPlugin(), // 每次打包之前清理 打包的文件
    // new DllReferencePlugin({
    //   context: __dirname,
    //   manifest: require('../dist/dll/common.manifest.json'),
    // }),
    // new AssetHtmlWebpackPlugin({
    //   filepath: path.resolve(__dirname, '../dist/dll/common.dll.js'),
    //   publicPath: 'dll',
    // }),
  ],
};
